import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.net.*;
import java.applet.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;


public class testapplet extends JApplet implements Runnable{
	
	private MapHost mh;
	private Player playa;
	private GameCanvas gameScreen;
	private Boolean going;
	private GameStatusBar statusBar;
	private GameSideBar sideBar;
	
	public void init(){
		
		going = false;
		MapHost mh = new MapHost(100, 100);
		mh.initWorld();
		
		playa = new Player("duud", 1, '@',270,270);
		playa.setFacing(1);
		mh.getMap(0).addCreature(playa);
		
		gameScreen = new GameCanvas(mh.getMap(0), playa);
		gameScreen.setVisible(true);
		gameScreen.setDoubleBuffered(true);
		
		statusBar = new GameStatusBar(playa);
		statusBar.setVisible(true);
		
		sideBar = new GameSideBar(playa);
		sideBar.setVisible(true);
		
		this.getContentPane().add(gameScreen).setBounds(0,0,600,600);
		this.getContentPane().add(statusBar).setBounds(0,600,100,600);
		this.getContentPane().add(sideBar).setBounds(600,0,400,700);
		
		this.getContentPane().addKeyListener(new KeyWatch());
		this.getContentPane().requestFocus();
		
		going = true;
		gameScreen.repaint();
	}
	
	public void run(){
		while(true){
			while(going == true){
				gameScreen.updateView();
				statusBar.repaint();
				sideBar.repaint();
			}
		}
	}
	
	public void start(){
	}
	public void stop(){
	}
	
	class KeyWatch extends KeyAdapter{
    	
	    public void keyPressed(KeyEvent evt){
	   		if(evt.getKeyCode() == 39){
	    		playa.move(2);
	    		gameScreen.repaint();
	    	}
	    	else if(evt.getKeyCode() == 37){
	    		playa.move(1);
	    		gameScreen.repaint();
	    	}
	    	else if(evt.getKeyCode() == 38){
	    		playa.move(3);
	    		gameScreen.repaint();
	    	}
	    	else if(evt.getKeyCode() == 40){
	    		playa.move(4);
	    		gameScreen.repaint();
	    	}
	  	}
	}
}